<?php
class simplePages extends module {
	public $title = "Simple editable pages";
	
	public function run() {
		$pageKey = $this->engine->getUrlParam(0);
		if (preg_match("/^[0-9a-zA-Z_]{1,30}$/", $pageKey)) {
			$pageData = $this->sql->getRowFromDB("SELECT title, keywords, description, content FROM simple_pages WHERE alias='".sql::e($pageKey)."' AND published='yes'");
			if ($pageData) {
				$this->xml->currentPageTitle = $pageData['title'];
				$this->xml->currentMetaKeywords = $pageData['keywords'];
				$this->xml->currentMetaDescription = $pageData['description'];
				$this->xml->content = $pageData['content'];
			} else {
				$this->engine->jump("/");
			}
		} else {
			$this->engine->jump("/");
		}
	}
	
	public function editableArea($pageKey=null) {
		$pageData = $this->sql->getRowFromDB("SELECT content FROM simple_pages WHERE alias='".sql::e($pageKey)."'");
		if ($pageData) $this->xml->content = $pageData['content'];
	}
}
?>